package org.fing.edu.uy.esbadp.modules.admAdaptation.mbean;

import java.sql.SQLException;
import java.util.List;

import org.fing.edu.uy.esbadp.core.AdpFlowTree;
import org.fing.edu.uy.esbadp.core.entity.DMRegisteredService;
import org.fing.edu.uy.esbadp.core.historic.FlowHistoricManager;
import org.fing.edu.uy.esbadp.modules.admAdaptation.AdpAdministrator;
import org.fing.edu.uy.esbadp.modules.persistance.ServiceManagerFactory;

public class EsbAdaptativeAdminServices implements 	EsbAdaptativeAdminServicesMBean {

	@Override
	public AdpFlowTree getAdpFlowForService(Long serviceID) throws SQLException {
		// busco el servicio que corresponde con el serviceID
		DMRegisteredService service = ServiceManagerFactory.getServiceManager().getVirtualService(serviceID);
		// busco la adaptacion existente
		AdpFlowTree adp = AdpAdministrator.getInstance().getAdpFlow(service.getEndPointURL());		
		return adp;
	}

	@Override
	public void setAdpFlowForService(AdpFlowTree flowTree, Long serviceID) throws SQLException {
		// busco el servicio que corresponde con el serviceID
		DMRegisteredService service = ServiceManagerFactory.getServiceManager().getVirtualService(serviceID);
		// agrego la adaptacion al Administrador
		AdpAdministrator.getInstance().addAdpFlow(service.getEndPointURL(), flowTree);
	}

	@Override
	public List<AdpFlowTree> getHistoricFlowTreeForService(Long serviceID) throws Exception {
		return FlowHistoricManager.getInstance().getHistoricFlowList(serviceID);
	}
	
	@Override
	public void clearHistoricFlowTreeForService(Long serviceID) throws Exception {
		 FlowHistoricManager.getInstance().clearHistoricFlowTreeForService(serviceID);
	}
	
	

}